//
//  ZZDataAnalysisVC.m
//  新项目
//
//  Created by liGordon on 17/3/7.
//  Copyright © 2017年 刘耀宗. All rights reserved.
//

#import "ZZDataAnalysisVC.h"
#import "ZZDataAnalysisCellTableViewCell.h"
#import "ZZFinanceAnalysisVC.h"
#import "ZZCustomAnalysisVC.h"
#import "ZZOrderVC.h"
#import "ZZGoodsAnalysisVC.h"
#import "ZZZZJVC.h"
#import "ZZZXGoodsAnalysisDetailVC.h"
#import "ZZCustomAnalysisVC.h"
#import "ChooseCarController.h"
static NSString * identifier = @"DataAnalysis";


@interface ZZDataAnalysisVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *menuTable;



@end

@implementation ZZDataAnalysisVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.menuTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.title = @"数据统计";
    _menuTable.delegate = self;
    _menuTable.dataSource = self;
    if (newwidth <= 320) {
        _menuTable.rowHeight = 107;
    }else if(newwidth <= 375 && newwidth >=320){
        _menuTable.rowHeight = 130;
    }else{
        _menuTable.rowHeight = 155;
    }
    //_menuTable.rowHeight = 120;
    [_menuTable registerNib:[UINib nibWithNibName:@"ZZDataAnalysisCellTableViewCell" bundle:nil] forCellReuseIdentifier:identifier];
 
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ZZDataAnalysisCellTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
   //cell = [[[UINib nibWithNibName:@"ZZDataAnalysisCellTableViewCell" bundle:nil]instantiateWithOwner:self options:nil]lastObject];
    if ((indexPath.row == 0)) {
        cell.titleLabel.text = @"财务数据";
        cell.detailLabel.text = @"精确的财务进账/出账记录";
    }else if(indexPath.row == 1){
            cell.titleLabel.text = @"客户分析";
        cell.detailLabel.text = @"忠实客户/新增客户统计";
    }else if(indexPath.row == 2){
              cell.titleLabel.text = @"商品数据";
        cell.detailLabel.text = @"查看热销/滞销商品";
    }else{
            cell.titleLabel.text = @"4";
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 3;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
//     ChooseCarController *vc = [[ChooseCarController alloc]init];
        
      //   ZZRepairFirstCostVC *vc = [[ZZRepairFirstCostVC alloc]init];
        ZZFinanceAnalysisVC *vc = [[ZZFinanceAnalysisVC alloc]init];
      //  ZZZZJVC *vc = [[ZZZZJVC alloc]init];
        PushVC(vc)
    }else if (indexPath.row == 1){
        ZZCustomAnalysisVC *vc = [[ZZCustomAnalysisVC alloc]init];
        PushVC(vc)
    }else if (indexPath.row == 2){
        ZZGoodsAnalysisVC *vc = [[ZZGoodsAnalysisVC alloc]init];
        PushVC(vc)
    }else{
        ZZZXGoodsAnalysisDetailVC *vc = [[ZZZXGoodsAnalysisDetailVC alloc]init];
        PushVC(vc)
    }
}
- (IBAction)DownBtnClick:(id)sender {
    NSArray *visibleCells = [self.menuTable visibleCells];
    __block NSInteger minRow = 0;
    [visibleCells enumerateObjectsUsingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSInteger row = [self.menuTable indexPathForCell:obj].row;
        if (idx == 0) {
            minRow = row;
        } else {
            if (minRow > row) {
                minRow = row;
            }
        }
    }];
    [self.menuTable scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:minRow + 1 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];

    
}
- (IBAction)upBtnClick:(id)sender {
    NSArray *visibleCells = [self.menuTable visibleCells];
    __block NSInteger maxRow = 0;
    [visibleCells enumerateObjectsUsingBlock:^(UITableViewCell *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSInteger row = [self.menuTable indexPathForCell:obj].row;
        if (idx == 0) {
            maxRow = row;
        } else {
            if (maxRow < row) {
                maxRow = row;
            }
        }
    }];
    [self.menuTable scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:maxRow - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];

    }

@end
